package com.ye.common.utils;

import com.ye.core.constant.Constants;

import java.io.Serializable;

/**
 * @Auther: baby
 * @Date: 2023/10/9 23:29
 * @Description:
 */
public class R<T> implements Serializable {

    private static final long serialVersionUID = -1482859690605337606L;

    /** 成功 */
    public static final int SUCCESS = Constants.SUCCESS;

    /** 失败 */
    public static final int FAIL = Constants.FAIL;
    private int code;
    private String msg;
    private T data;

    private R() {
    }

    private R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static  <T> R<T> ok(){
        return new R<>(Constants.SUCCESS,"请求成功",null);
    }

    public static  <T> R<T> ok(T data){
        return new R<>(Constants.SUCCESS,"请求成功",data);
    }
    public static  <T> R<T> ok(String msg,T data){
        return new R<>(Constants.SUCCESS,msg,data);
    }
    public static  <T> R<T> fail(){
        return new R<>(Constants.FAIL,"网络异常请,请等待。。。",null);
    }
    public static  <T> R<T> fail(String msg){
        return new R<>(Constants.FAIL,msg,null);
    }
    public static  <T> R<T> fail(int code,String msg){
        return new R<>(code,msg,null);
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
